package com.Arsanesia.TempleRush.Views.Screens;

import com.Arsanesia.TempleRush.TempleRush;
import com.Arsanesia.TempleRush.Controllers.Listeners.GameOverListener;
import com.Arsanesia.TempleRush.Models.Profile;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.g2d.TextureAtlas;
import com.badlogic.gdx.graphics.g2d.TextureRegion;
import com.badlogic.gdx.scenes.scene2d.ui.Image;
import com.badlogic.gdx.scenes.scene2d.utils.TextureRegionDrawable;

public class GameOverScreen extends AbstractScreen{

	private final float TEMPLE_BUILTY = VIEWPORT_DEFAULTHEIGHT/2 + 2;
	private final float CURRENT_TEMPLEY = TEMPLE_BUILTY + 77;
	private final float CURRENT_SCOREY = VIEWPORT_DEFAULTHEIGHT/2  - 73 ;
	private final float HIGH_SCOREY = CURRENT_SCOREY - 73;
	
	private Image gameOverImage;
	private Profile profile;

	public GameOverScreen(TempleRush game) {
		super(game);
	}
	@Override
	public void show(){
		super.show();
		profile = game.getProfileManager().retrieveProfile();
		//persistence the profile after game ends
    	game.getProfileManager().persist();
    	//add game over image
		atlas = new TextureAtlas(Gdx.files.internal("Images/GameOver/gameover.atlas"));
		gameOverImage = new Image(new TextureRegionDrawable(new TextureRegion(atlas.createSprite("gameoverscreen"))));
		gameOverImage.addListener(new GameOverListener(game));
		this.addActor(gameOverImage);
	}

	@Override
	public void render(float delta){
		super.render(delta);
		this.getSpriteBatch().begin();
		font.draw(this.getSpriteBatch(), profile.getCurrentTemple()+"", VIEWPORT_DEFAULTWIDTH/2, CURRENT_TEMPLEY);
        font.draw(this.getSpriteBatch(), profile.getTempleBuilt()+"", VIEWPORT_DEFAULTWIDTH/2,TEMPLE_BUILTY);
        font.draw(this.getSpriteBatch(), profile.getCurrentScore()+"", VIEWPORT_DEFAULTWIDTH/2, CURRENT_SCOREY);
		font.draw(this.getSpriteBatch(), profile.getHighScore()+"", VIEWPORT_DEFAULTWIDTH/2,  HIGH_SCOREY);
		this.getSpriteBatch().end(); 
	}

}
